﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SMS.BLL;

namespace SMS.SMPPClient
{
    public partial class SendSms : Form
    {
        private string _msgInfo;
        private Gateway frmGateway;

        public SendSms(Gateway frm)
        {
            InitializeComponent();
            this.frmGateway = frm;
        }

        private void SendSms_Load(object sender, EventArgs e)
        {
            this.cboContentType.SelectedIndex = 0;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (!this.frmGateway.clientSoc.Soc.Connected)
                this.lblStatus.Text = "Status: Cannot connect to SMSC";
            
            else
            {
                try
                {
                    this._msgInfo = this.txtContent.Text;
                    int contentType = Convert.ToInt32(this.cboContentType.Items[this.cboContentType.SelectedIndex].ToString().Substring(0, 1));
                    lock (this.frmGateway.MsgOutWorkQueue)
                    {
                        this.frmGateway.MsgOutWorkQueue.Add(new MsgOutWorkQueue(0, this.txtMobileNo.Text.Trim(), SMS.BLL.Util.GetAppSettings("TestNum"), this._msgInfo, contentType, this.frmGateway));
                    }
                }
                catch (Exception ex)
                {
                    this.lblStatus.Text = "Status: " + ex.Message;
                }
            }
        }

        private void txtContent_TextChanged(object sender, EventArgs e)
        {
            this.lblContentLength.Text = "Length: " + this.txtContent.Text.Length.ToString();
        }
    }
}